<?php
/**
* @version		$Id: view.html.php 196926529 2011-07-20 02:46:31 dothithoit06@gmail.com $
* @package		Joomla 1.5.x
* @subpackage	Htbn_don_dat_hangs
* @copyright	Copyright (C) 2010 - 2011 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

jimport( 'joomla.application.component.view');
jimport('joomla.html.pane');

/**
 * HTML View class for the Htbn_don_dat_hangs component
 *
 * @static
 * @package		Joomla 1.5.x
 * @subpackage	Htbn_don_dat_hangs
 */
class Htbn_don_dat_hangsViewHtbn_don_dat_hang extends JView
{
	function display($tpl = null)
	{
		global $mainframe;

		if($this->getLayout() == 'form') {
			$this->_displayForm($tpl);
			return;
		}

		//get the htbn_don_dat_hang
		$htbn_don_dat_hang =& $this->get('data');

		if ($htbn_don_dat_hang->url) {
			// redirects to url if matching id found
			$mainframe->redirect($htbn_don_dat_hang->url);
		}

		parent::display($tpl);
	}

	function _displayForm($tpl)
	{
		global $mainframe, $option;

		$db		=& JFactory::getDBO();
		$uri 	=& JFactory::getURI();
		$user 	=& JFactory::getUser();
		$model	=& $this->getModel();
		
		$editor =& JFactory::getEditor();
		
		JHTML::_('behavior.calendar');
		JHTML::_('behavior.modal', 'a.modal-button');
		$button = new JObject();
		$button->set('modal', true);
		$button->set('modalname', 'modal-button');
		$button->set('options', "{handler: 'iframe', size: {x: 760, y: 520}}");

		$lists = array();

		//get the htbn_don_dat_hang
		$htbn_don_dat_hang	=& $this->get('data');
		$isNew		= ($htbn_don_dat_hang->wts_htbn_don_dat_hang_id < 1);

		// Edit or Create?
		if ($isNew) {
			// initialise new record
			$htbn_don_dat_hang->published = 1;
		}
		
		// helper		 
		require_once "components/com_htbn_chi_tiet_don_dat_hang/helpers/htbn_chi_tiet_don_dat_hang_active_checkbox.php";
		Htbn_chi_tiet_don_dat_hang_active_checkboxHelper::load($htbn_don_dat_hang->wts_htbn_don_dat_hang_id);
		
		// build the html select list
		$lists['published'] 		= JHTML::_('select.booleanlist',  'published', 'class="inputbox"', $htbn_don_dat_hang->published );

		$lists['created'] 		 	= $htbn_don_dat_hang->created?JHTML::_('date', $htbn_don_dat_hang->created, '%Y-%m-%d %H:%M:%S'):'';

		$lists['modified'] 		 	= $htbn_don_dat_hang->modified?JHTML::_('date', $htbn_don_dat_hang->modified, '%Y-%m-%d %H:%M:%S'):'';

		// build the html select list for ordering
		$query = 'SELECT ordering AS value, wts_htbn_don_dat_hang_id AS text'
			. ' FROM #__htbn_don_dat_hangs'
			. ' ORDER BY ordering';
		$lists['ordering'] 			= JHTML::_('list.specificordering',  $htbn_don_dat_hang, $htbn_don_dat_hang->wts_htbn_don_dat_hang_id, $query );

		$lists['ngay_gio_dat'] 		 	= $htbn_don_dat_hang->ngay_gio_dat?JHTML::_('date', $htbn_don_dat_hang->ngay_gio_dat, '%Y-%m-%d'):'';
		$lists['ngay_gio_lay'] 		 	= $htbn_don_dat_hang->ngay_gio_lay?JHTML::_('date', $htbn_don_dat_hang->ngay_gio_lay, '%Y-%m-%d'):'';
		
		$this->assignRef('lists', $lists);
		$this->assignRef('htbn_don_dat_hang', $htbn_don_dat_hang);
		$this->assignRef('button', $button);
		$this->assignRef('editor', $editor);
		$this->assign('action', $uri->toString());
		
		$paramfile 	= JPath::clean(JPATH_COMPONENT.'/views/htbn_don_dat_hang/params.xml');
		$params = new JParameter(@$htbn_don_dat_hang->params, $paramfile);
		$sliders = JPane::getInstance('sliders');
		$this->assignRef('pane', $sliders);
		$this->assignRef('params', $params);

		parent::display($tpl);
	}
}
